package cn.flexui.flexuiserver.ai.memory;

import cn.flexui.flexuiserver.domain.entity.ChatCodeRecord;
import cn.flexui.flexuiserver.service.ChatCodeRecordService;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wanmingyu
 * @create 2024/9/26 21:20
 */
@Component
public class CodeChatMemory implements ChatMemory {

    @Autowired
    private ChatCodeRecordService chatCodeRecordService;

    @Override
    public void add(String conversationId, List<Message> messages) {

    }

    @Override
    public List<Message> get(String conversationId, int lastN) {
        ChatCodeRecord chatCodeRecord = chatCodeRecordService.getByRequestIdOne(conversationId);
        if (chatCodeRecord == null) {
            return List.of();
        }
        return List.of(new UserMessage(chatCodeRecord.getCode()));
    }

    @Override
    public void clear(String conversationId) {

    }
}
